unit editpageform;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, BCLabel, BCButton, TplEditUnit, TplSpinEditUnit,
  TplCheckBoxUnit, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;

type

  { TfrmEditPage }

  TfrmEditPage = class(TForm)
    BCButton2: TBCButton;
    BCLabel1: TBCLabel;
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    CheckBox1: TplCheckBox;
    Edit1: TplEdit;
    Edit2: TplEdit;
    Spin1: TplSpinEditInteger;
    procedure BCButton2Click(Sender: TObject);
    procedure BCLabel1Click(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
    procedure FormShow(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Image1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer
      );
    procedure Image1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    Moving:boolean;
    XPos,YPos:integer;
  public

  end;

var
  frmEditPage: TfrmEditPage;

implementation

{$R *.frm}

{ TfrmEditPage }

procedure TfrmEditPage.BCLabel1Click(Sender: TObject);
begin
  ModalResult:=mrCancel;
end;

procedure TfrmEditPage.FormCloseQuery(Sender: TObject; var CanClose: boolean);
begin
  if ModalResult=mrOK then
  begin
    if Trim(Edit1.Text)='' then
    begin
      MessageDlg('请输入描述。',mtWarning,[mbOK],0);
      Edit1.SetFocus;
      CanClose:=False;
      Exit;
    end;
    if Trim(Edit2.Text)='' then
    begin
      MessageDlg('请输入网址。',mtWarning,[mbOK],0);
      Edit2.SetFocus;
      CanClose:=False;
      Exit;
    end;
    if Pos('http',Lowercase(Trim(Edit2.Text)))<>1 then
    begin
      MessageDlg('网址须以http开头，请补充完整。',mtWarning,[mbOK],0);
      Edit2.SetFocus;
      CanClose:=False;
      Exit;
    end;
    if CheckBox1.Checked then
    begin
      if pos('&kiosk', trim(Edit2.Text))<1 then
      begin
        Edit2.Text:=Edit2.Text+'&kiosk';
      end;
    end;
  end;
end;

procedure TfrmEditPage.FormShow(Sender: TObject);
begin
  Edit1.SetFocus;
end;

procedure TfrmEditPage.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if mbLeft = Button then
  begin
    Self.Moving:=True;
    Self.YPos := Y;
    Self.XPos := X;
  end;
end;

procedure TfrmEditPage.Image1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if not (csDesigning in Self.ComponentState) then
  begin
    if Self.Moving then
    begin
      Self.Top:=Self.Top+Y-Self.YPos;
      Self.Left:=Self.Left+X-Self.XPos;
      if Self.Top<0 then
        Self.Top:=0;
    end;
  end;
end;

procedure TfrmEditPage.Image1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  Moving:=False;
end;

procedure TfrmEditPage.BCButton2Click(Sender: TObject);
begin
  ModalResult:=mrOK;
end;

end.

